import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/subscription/model/subscription_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:tender_flutter/widgets/text_highlight.dart';

class SubscriptionGroupListCell extends StatelessWidget {
  final SubscriptionList data;
  final GestureTapCallback onTapCallback;
  final GestureTapCallback exportCallback;
  final VoidCallback editCallback;
  final VoidCallback deleteCallback;

  const SubscriptionGroupListCell(
      {Key key,
      this.data,
      this.onTapCallback,
      this.exportCallback,
      this.editCallback,
      this.deleteCallback})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    return Slidable(
        actionPane: SlidableDrawerActionPane(),
        actionExtentRatio: 0.2,
        secondaryActions: <Widget>[
          IconSlideAction(
            caption: '编辑',
            color: ThemeColors.colorType6,
            icon: Icons.edit,
            onTap: editCallback,
          ),
          IconSlideAction(
            caption: '删除',
            color: ThemeColors.colorType30,
            icon: Icons.delete,
            onTap: deleteCallback,
          ),
        ],
        child: GestureDetector(
          onTap: onTapCallback,
          child: Container(
            margin: EdgeInsets.symmetric(
                horizontal: ScreenAdapter.width(30),
                vertical: ScreenAdapter.height(10)),
            decoration: BoxDecoration(
                color: ThemeColors.colorWhite,
                borderRadius: BorderRadius.circular(ScreenAdapter.width(14))),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                    height: ScreenAdapter.height(76),
                    padding: EdgeInsets.symmetric(
                        horizontal: ScreenAdapter.width(30)),
                    decoration: BoxDecoration(
                        color: ThemeColors.colorType6,
                        borderRadius: BorderRadius.only(
                            topRight: Radius.circular(ScreenAdapter.width(14)),
                            topLeft: Radius.circular(ScreenAdapter.width(14)))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Row(children: [
                          Image.asset(RPath.imgPath + "icon_s_time.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(26),
                              height: ScreenAdapter.width(26)),
                          SizedBox(width: ScreenAdapter.width(10)),
                          Text(
                            (data.begin ?? "-"),
                            maxLines: 1,
                            style: TextStyle(
                                color: ThemeColors.colorWhite,
                                fontSize: ScreenAdapter.sp(26),
                                fontWeight: FontWeight.w500),
                          )
                        ]),
                        Row(children: [
                          Image.asset(RPath.imgPath + "icon_s_address.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(26),
                              height: ScreenAdapter.width(26)),
                          SizedBox(width: ScreenAdapter.width(10)),
                          Text(
                            getListStr(data.areas),
                            maxLines: 1,
                            style: TextStyle(
                                color: ThemeColors.colorWhite,
                                fontSize: ScreenAdapter.sp(26),
                                fontWeight: FontWeight.w500),
                          )
                        ]),
                      ],
                    )),
                SizedBox(height: ScreenAdapter.height(40)),
                Container(
                    padding: EdgeInsets.symmetric(
                        horizontal: ScreenAdapter.width(30)),
                    child: Row(children: [
                      Image.asset(RPath.imgPath + "icon_keyword.png",
                          fit: BoxFit.contain,
                          width: ScreenAdapter.width(35),
                          height: ScreenAdapter.width(35)),
                      SizedBox(width: ScreenAdapter.width(15)),
                      Expanded(
                          child: Text(
                        (data.keyword ?? []).join("   "),
                        maxLines: 3,
                        style: TextStyle(
                            color: ThemeColors.colorType24,
                            fontSize: ScreenAdapter.sp(32),
                            fontWeight: FontWeight.w500),
                      )),
                      // Expanded(
                      //     child: SizedBox(
                      //   width: double.infinity,
                      // )),
                      Offstage(
                        offstage: !data.isPoint,
                        child: Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: ScreenAdapter.width(10),
                              vertical: ScreenAdapter.width(5)),
                          decoration: BoxDecoration(
                              color: ThemeColors.colorType17,
                              borderRadius: BorderRadius.circular(
                                  ScreenAdapter.width(20))),
                          child: Text(
                            "${data.num > 1000 ? "999+" : data.num}",
                            style: TextStyle(
                                color: ThemeColors.colorWhite,
                                fontSize: ScreenAdapter.sp(26),
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                      )
                    ])),
                Offstage(
                    offstage: isEmpty(data.lastTitle) ? true : false,
                    child: Container(
                        margin: EdgeInsets.only(top: ScreenAdapter.height(20)),
                        padding: EdgeInsets.symmetric(
                            horizontal: ScreenAdapter.width(30)),
                        child: TextHighlight(
                          maxLines: 1,
                          content: data.lastTitle ?? "-",
                          keyWords: [],
                          normalStyle: TextStyle(
                              color: ThemeColors.colorType2,
                              fontSize: ScreenAdapter.sp(26),
                              fontWeight: FontWeight.w500),
                          highlightStyle: TextStyle(
                              color: ThemeColors.colorType56,
                              fontSize: ScreenAdapter.sp(26),
                              fontWeight: FontWeight.w500),
                        ))),
                SizedBox(height: ScreenAdapter.height(40)),
              ],
            ),
          ),
        ));
  }
  //
  // List<Widget> _getTagsList() {
  //   List<Widget> lists = [];
  //   if (data.areas != null && data.areas.isNotEmpty) {
  //     lists.add(_getTag(
  //         data.areas[0], ThemeColors.colorType20, ThemeColors.colorType40));
  //   }
  //   if (data.types != null && data.types.isNotEmpty) {
  //     lists.add(_getTag(data.types.join(","), ThemeColors.colorType41,
  //         ThemeColors.colorType42));
  //   }
  //   if (data.biddingClasses != null && data.biddingClasses.isNotEmpty) {
  //     lists.add(_getTag(data.biddingClasses.join(","), ThemeColors.colorType15,
  //         ThemeColors.colorType16));
  //   }
  //   if (data.industries != null && data.industries.isNotEmpty) {
  //     lists.add(_getTag(data.industries.join(","), ThemeColors.colorType54,
  //         ThemeColors.colorType53));
  //   }
  //   return lists;
  // }

  Widget _getTag(String conent, Color bgColor, Color textColor) {
    return Container(
      // constraints: BoxConstraints(
      //   maxWidth: ScreenAdapter.width(135),
      // ),
      margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
      padding: EdgeInsets.only(
          left: ScreenAdapter.width(20),
          right: ScreenAdapter.width(20),
          top: ScreenAdapter.width(10),
          bottom: ScreenAdapter.width(10)),
      child: Text(conent,
          overflow: TextOverflow.ellipsis,
          style: TextStyle(color: textColor, fontSize: ScreenAdapter.sp(24))),
      decoration: BoxDecoration(
          color: bgColor, borderRadius: new BorderRadius.circular(3)),
    );
  }
}
